package org.csu.logistics.Service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.csu.logistics.entity.User;
import org.csu.logistics.entity.log;
import org.csu.logistics.persistence.LogMapper;
import org.csu.logistics.persistence.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("LogService")
public class LoginServiceImp implements LogService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    LogMapper logMapper;


    @Override
    public boolean judgeUserid(String userid) {
        if(logMapper.selectById(userid)== null){
            return true;
        }
        return false;
    }

    @Override
    public void insert_account(User user) {
        userMapper.insert(user);
    }

    @Override
    public void insert_log(log log) {
        logMapper.insert(log);
    }

    @Override
    public void change_password(String email,String pwd) {

        UpdateWrapper<log> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("email",email).set("pwd", pwd);
        logMapper.update(null, updateWrapper);
    }

    @Override
    public boolean judgeIFLogin(int userid, String pwd, int aut) {
        UpdateWrapper<log> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("userid",userid).eq("pwd",pwd).eq("authority",aut);
        System.out.println(logMapper.selectList(updateWrapper));
        if(logMapper.selectList(updateWrapper).isEmpty()){
            return false;
        }
        else{
            return true;
        }
    }

}
